//
//  HSOrderModel.m
//  hsdyOrderSystem
//
//  Created by XunFengKJ on 2017/11/11.
//  Copyright © 2017年 赖国锋. All rights reserved.
//

#import "HSOrderModel.h"
#import "HSOrderDetailModel.h"
@implementation HSOrderModel

- (instancetype)initWithDictionary:(NSDictionary *)dict{
    
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
        NSDictionary *stringToArr = [self dictionaryWithJsonString:dict[@"foodsList"]];
        _foodsList = [HSOrderDetailModel footWithArray:(NSArray*)stringToArr];
    }
    return self;
}

+ (NSMutableArray *)orderWithArray:(NSArray *)array
{
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < array.count; i ++)
    {
        NSDictionary *dict = array[i];
        HSOrderModel *Model = [self orderModelWithDictionary:dict];
        [arrayM addObject:Model];
    }
    return arrayM;
}


+ (instancetype)orderModelWithDictionary:(NSDictionary *)dict;{
    
    return [[self alloc] initWithDictionary:dict];
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}


//字符串转json
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err){
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

@end
